#include "InfoState.h"
#include "TestState.h"
#include "Game.h"
#include "ScreenManager.h"
#include "DX11TextureManager.h"
#include "DX11HelpfulFunctions.h"

InfoState::InfoState()
{
	m_screenSize.x = (float)TheScreenManager::Instance()->GetWindowWidth();
	m_screenSize.y = (float)TheScreenManager::Instance()->GetWindowHeight();
	m_retKeyDown = false;

	m_enterToContinue.SetFont("pixel_small", L"../../Assets/pixel2.png");
	m_enterToContinue.Translate(D3DXVECTOR3(0.0f, -0.9f, 0.0f));
	m_enterToContinue.Update(" Hit Enter Key To Continue");

	m_soundModsTitle.SetFont("pixel_small", L"../../Assets/pixel2.png");
	m_soundModsTitle.Translate(D3DXVECTOR3(0.0f, 0.5f, 0.0f));
	m_soundModsTitle.Update(" ------Sound Modifiers------");
	m_soundModsL1.SetFont("pixel_small", L"../../Assets/pixel2.png");
	m_soundModsL1.Translate(D3DXVECTOR3(0.0f, 0.4f, 0.0f));
	m_soundModsL1.Update(" Sound Modifiers change the volume, Low-Pass Filter");
	m_soundModsL2.SetFont("pixel_small", L"../../Assets/pixel2.png");
	m_soundModsL2.Translate(D3DXVECTOR3(0.0f, 0.3f, 0.0f));
	m_soundModsL2.Update(" amount and the sample rate of the sound signal.");
	m_soundModsL3.SetFont("pixel_small", L"../../Assets/pixel2.png");
	m_soundModsL3.Translate(D3DXVECTOR3(0.0f, 0.3f, 0.0f));
	m_soundModsL3.Update(" To change the values click and dragon the bars.");

	m_sampleSoundTitle.SetFont("pixel_small", L"../../Assets/pixel2.png");
	m_sampleSoundTitle.Translate(D3DXVECTOR3(0.0f, 0.0f, 0.0f));
	m_sampleSoundTitle.Update(" ------Sample sounds------");
	m_sampleSoundsL1.SetFont("pixel_small", L"../../Assets/pixel2.png");
	m_sampleSoundsL1.Translate(D3DXVECTOR3(0.0f, -0.1f, 0.0f));
	m_sampleSoundsL1.Update(" Click on a sound to select it.");

	m_controllersTitle.SetFont("pixel_small", L"../../Assets/pixel2.png");
	m_controllersTitle.Translate(D3DXVECTOR3(0.0f, -0.5f, 0.0f));
	m_controllersTitle.Update(" ------Controllers------");
	m_controllersL1.SetFont("pixel_small", L"../../Assets/pixel2.png");
	m_controllersL1.Translate(D3DXVECTOR3(0.0f, -0.6f, 0.0f));
	m_controllersL1.Update(" The Controllers allow you to save, load, play,");
	m_controllersL2.SetFont("pixel_small", L"../../Assets/pixel2.png");
	m_controllersL2.Translate(D3DXVECTOR3(0.0f, -0.7f, 0.0f));
	m_controllersL2.Update(" normalise or reverse the sound signal.");
	// normalise or reverse the sound singal
}

void InfoState::Draw()
{
	TheScreenManager::Instance()->GetDeviceContext()->OMSetRenderTargets(1, 
		TheScreenManager::Instance()->GetRenderTargetview(),
		TheScreenManager::Instance()->GetDepthStencilView());
		
	DX11::ClearColour(1.0f, 1.0f, 1.0f, 1.0f);

	D3DXMATRIX m_view;
	D3DXMATRIX m_proj;

	D3DXMatrixLookAtLH(&m_view, &D3DXVECTOR3(0.0f, 0.0f, 1.0f), 
		&D3DXVECTOR3(0.0f, 0.0f, 0.0f), 
		&D3DXVECTOR3(0.0f, 1.0f, 0.0f));
	
	D3DXMatrixOrthoLH(&m_proj, m_screenSize.x, m_screenSize.y, 0, 100);

	TheScreenManager::Instance()->SetViewProjMatrix(m_view, m_proj);
			
	TheScreenManager::Instance()->EnableBlending();
	TheObjMeshManager::Instance()->ChangeTexture("title_quad",
		TheDX11TextureManager::Instance()->UseTexture(L"../../Assets/info_image.png"));
	//TheObjMeshManager::Instance()->Translate("title_quad", D3DXVECTOR3(0.0f, -1.0f, rot));
	TheObjMeshManager::Instance()->Scale("title_quad", D3DXVECTOR3(m_screenSize.x, m_screenSize.y, 1.0f));
	//TheObjMeshManager::Instance()->Rotate("title_quad", M_PI_4, 1.0f, 0.0f, 0.0f);
	TheObjMeshManager::Instance()->Draw("title_quad");
	TheScreenManager::Instance()->DisableBlending();

	m_enterToContinue.Draw();

	m_soundModsTitle.Draw();
	m_soundModsL1.Draw();
	m_soundModsL2.Draw();
	m_soundModsL3.Draw();

	m_sampleSoundTitle.Draw();
	m_sampleSoundsL1.Draw();

	m_controllersTitle.Draw();
	m_controllersL1.Draw();
	m_controllersL2.Draw();
}

void InfoState::Update()
{
	if (m_retKeyDown)
	{
		TheGame::Instance()->SetGameState(TheTestState::Instance());
	}
}

void InfoState::OnActivated()
{
	m_retKeyDown = false;
	TheEventPoller::Instance()->AddHandler(this);
}

void InfoState::OnDeactivated()
{
	m_retKeyDown = false;
	TheEventPoller::Instance()->RemoveHandler(this);
}

void InfoState::OnKeyDownEvent(const WPARAM& event)
{
	if (event == VK_RETURN)
	{
		// go to test state
		m_retKeyDown = true;
	}
}